home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 02 / vlabel.asm < prev    next >
Assembly Source File  |  1990-09-17  |  5KB  |  109 lines

  1.         PAGE    ,105
  2.         TITLE   VLABEL Function
  3.         .MODEL  MEDIUM
  4. ;***********************************************************************
  5. ;                              VLABEL.ASM                              *
  6. ;   VLABEL (<drive>) [DECLARE FUNCTION VLABEL$ (A$)] is an assembled   *
  7. ; string function to be linked to programs written in Microsoft BASIC  *
  8. ; v. 7.0, or later.  When given a valid drive code as an argument, it  *
  9. ; returns a string containing the volume label.                        *
  10. ;   VLABEL uses the first character of the string argument as the code *
  11. ; for the requested drive.  If the disk in that drive has no label (or *
  12. ; no such drive exists), VLABEL will return a null string.  If the     *
  13. ; code refers to a diskette drive with the door open, the calling      *
  14. ; BASIC program will be interrupted with a BASIC "Disk not ready"      *
  15. ; error interrupt.                                                     *
  16. ;                   Written by M. L. Lesser, 4/27/90                   *
  17. ;                 Assembled with Microsoft MASM v. 5.1                 *
  18. ;***********************************************************************
  19.  
  20.         EXTRN StringAddress: FAR
  21.         EXTRN StringAssign:  FAR
  22.         EXTRN StringLength:  FAR
  23.         EXTRN StringRelease: FAR
  24.  
  25. .DATA
  26. FCB     DB      0FFH                    ;Use extended FCB format to
  27.         DB      5 DUP(0)                ;   avoid unwanted period.
  28.         DB      8                       ;Label attribute
  29. DRIVE   DB      0                       ;Drive code goes here
  30. FLABEL  DB      11 DUP(?)               ;Dummy file name
  31.         DB      21 DUP(?)               ;Remaining FCB filler
  32. DESCRIP DD      0                       ;BASIC string descriptor
  33.  
  34. .CODE
  35.         PUBLIC VLABEL
  36. VLABEL  PROC
  37.         PUSH    BP
  38.         MOV     BP,SP
  39.         PUSH    DS
  40.         PUSH    DI
  41.         MOV     AH,2FH                  ;Get and save BASIC's DTA
  42.         INT     21H
  43.         PUSH    BX                      ;DTA offset
  44.         PUSH    ES                      ;DTA segment
  45. ;  Check for non-null input string (drive code):
  46.         PUSH    6[BP]                   ;Input string descriptor pointer
  47.         CALL    StringLength            ;Get length
  48.         OR      AX,AX                   ;Is it zero?
  49.         JZ      NODRV                   ;If so, skip getting drive code
  50. ;  Locate address of input string:
  51.         PUSH    6[BP]
  52.         CALL    StringAddress
  53.         MOV     DS,DX                   ;Move string address to DS:BX
  54.         MOV     BX,AX
  55.         MOV     AL,[BX]                 ;  and drive letter to AL
  56.         AND     AL,5FH                  ;Make drive character upper case
  57.         SUB     AL,40H                  ;Convert to FCB drive code
  58. ;  Set up extended FCB to find label:
  59. NODRV:  MOV     BX,SS                   ;Restore DGROUP addressability
  60.         MOV     DS,BX                   ;  to DS and ES
  61.         MOV     ES,BX
  62.         MOV     DRIVE,AL                ;Load drive number in FCB:
  63.         LEA     DI,FLABEL               ;Load FLABEL portion of FCB with
  64.         MOV     AL,'?'                  ;  question marks
  65.         MOV     CX,11
  66.         REP     STOSB
  67. ;  Find the first file containing a label (there is only one!):
  68.         LEA     DX,FCB                  ;Set DTA to FCB
  69.         MOV     AH,1AH
  70.         INT     21H
  71.         MOV     AH,11H                  ;Find first
  72.         INT     21H
  73.         OR      AL,AL                   ;Will be zero if label found
  74.         JNZ     NULLIT                  ;If not, send zero-length string
  75. ; Decrease CX by count of trailing blanks in label:
  76.         MOV     CX,11
  77.         MOV     AL,' '
  78.         DEC     DI                      ;Restore DI to end of label
  79.         STD                             ;Scan "down"
  80.         REPZ    SCASB
  81.         INC     CX                      ;Include "last" non-blank
  82.         CLD                             ;Restore cleared direction flag
  83. ; Convert label to BASIC string
  84.         PUSH    DS                      ;Far address of MASM string
  85.         LEA     AX,FLABEL
  86.         PUSH    AX
  87.         PUSH    CX                      ;Length of string
  88.         PUSH    DS                      ;Far address of descriptor
  89.         LEA     AX,DESCRIP
  90.         PUSH    AX
  91.         XOR     AX,AX                   ;Zero-length copies MASM string
  92.         PUSH    AX                      ; into BASIC string space 
  93.         CALL    StringAssign
  94. DIVOTS: POP     DS                      ;Restore BASIC's DTA
  95.         POP     DX
  96.         MOV     AH,1AH
  97.         INT     21H
  98.         POP     DI                      ;Restore registers
  99.         POP     DS
  100.         POP     BP
  101.         LEA     AX,DESCRIP              ;Return near address to BASIC
  102.         RET     2
  103. NULLIT: LEA     AX,DESCRIP              ;Make BASIC string null
  104.         PUSH    AX
  105.         CALL    StringRelease
  106.         JMP     DIVOTS
  107. VLABEL  ENDP
  108.         END
  109.